/*
 * @Author: c
 * @Date: 2024-01-16 04:52:56
 * @LastEditTime: 2024-01-27 01:31:20
 * @LastEditors: c
 * @Description: 
 * @FilePath: \music-web-backend\src\core\system\minio\dto\create-file.dto.ts
 * https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
// Copyright 2024 Administrator
// 
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// 
//     http://www.apache.org/licenses/LICENSE-2.0
// 
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

import { Transform } from "class-transformer";
import { IsBoolean, IsEnum, IsNotEmpty, IsNumber, IsOptional, IsString } from "class-validator";
import { MimeEnum, StatusTypeEnum } from "../enum";

export class ResourceType {
    //是否是公共访问的资源
    @IsOptional()
    @Transform(v => {
        console.log("isPublic", v)
        return eval(v)
    })
    @IsBoolean({ message: "是否公共访问必填" })
    isPublic: boolean = false;
}

export class FileDescDto extends ResourceType {

    //创建者username
    @IsOptional()
    creator: string

    //文件名称
    @IsNotEmpty({
        message: "文件名称不能为空"
    })
    @IsString({
        message: "必须是字符串"
    })
    // @Transform(value=>encodeURI(value))
    name: string;

    //浏览器读取文件的时间戳
    @IsOptional()
    @Transform(value => {
        return +value
    })
    @IsNumber({ allowNaN: false, allowInfinity: false }, {
        message: "必须是数字"
    })
    uid: number;

    //上传进度
    @IsOptional()
    @Transform(value => {
        return +value
    })
    @IsNumber()
    percentage: number;

    //文件的状态
    @IsOptional()
    @IsEnum(StatusTypeEnum, { message: "类型不正确" })
    status: StatusTypeEnum;

    //文件大小
    @IsOptional()
    @Transform(value => {
        return +value
    })
    @IsNumber()
    size: number;

    //文件的链接/本地的或者远程的
    @IsOptional()
    @IsString({
        message: "必须是字符串"
    })
    url: string;

    //文件最后修改时间
    @IsOptional()
    @Transform(value => {
        return +value
    })
    @IsNumber({ allowNaN: false, allowInfinity: false }, {
        message: "必须是数字"
    })
    lastModified: number;

    //文件mime类型
    @IsOptional()
    @IsEnum(MimeEnum, { message: "文件类型不正确" })
    type: MimeEnum;




}


